package net.yvesd.cellhunter.persistance;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

/**
 * Copied from http://www.roseindia.net/java/beginners/CopyFile.shtml
 * 
 * @author http://www.roseindia.net/java/beginners/CopyFile.shtml
 * 
 */
public class CopyFile {
	
	public static String copyfile(File sr, File dt) {
		try {
			InputStream in = new FileInputStream(sr);

			// For Append the file.
			// OutputStream out = new FileOutputStream(f2,true);

			// For Overwrite the file.
			OutputStream out = new FileOutputStream(dt);

			byte[] buf = new byte[1024];
			int len;
			while ((len = in.read(buf)) > 0) {
				out.write(buf, 0, len);
			}
			in.close();
			out.close();
			return "OK";
		} catch (FileNotFoundException ex) {
			return "FileNotFoundException: " + ex.getMessage();
		} catch (IOException e) {
			return "IOException: " + e.getMessage();
		}
	}
}